package com.iflytek.uoamp.notify.core.protocol;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.iflytek.uoamp.common.notify.obj.Notification;
import com.iflytek.uoamp.common.notify.obj.NotifyInfo;

public class DirectNotification extends Notification {
	
    private static final long serialVersionUID = 2851562548481047428L;
    
    private List<String> content;
    
    @JSONField(name = "plugin_nodes")
    public List<DirectPluginNode> pluginNodes;

    public List<String> getContent() {
        return content;
    }

    public void setContent(List<String> content) {
        this.content = content;
    }

    public List<DirectPluginNode> getPluginNodes() {
        return pluginNodes;
    }

    public void setPluginNodes(List<DirectPluginNode> plugins) {
        this.pluginNodes = plugins;
    }
    
    public NotifyInfo toNotifyInfo(List<?> contents) {
        NotifyInfo info = new NotifyInfo();
        
		if (contents != null) {
			if(contents.size() == 4){
				info.setNotifyHost(Arrays.asList((String)contents.get(1)));
				info.setNotifyName((String)contents.get(2));
				info.setContent((String)contents.get(3));
			}else if(contents.size() == 5){
				info.setNotifyHost(Arrays.asList((String)contents.get(2)));
				info.setNotifyName((String)contents.get(3));
				info.setContent((String)contents.get(4));
			}
			else{
				info.setNotifyHost(new ArrayList<String>());
				info.setNotifyName("");
			}
			
			info.setState(state);
			GregorianCalendar c = new GregorianCalendar();
			c.setTimeInMillis(System.currentTimeMillis());
			info.setCreatedTime(c.getTime());
		}
        
        return info;
    }
}
